not executing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

not executing

import java.util.*; class Student { int sno; String sname; int m; int p; int c; } void input() { Scanner s=new Scanner(System.in); System.out.print("Enter the student number:"); sno=s.nextInt(); System.out.print("Enter the student name:"); sname=s.nextLine(); System.out.print("Enter maths marks:"); m=s.nextInt(); System.out.print("Enter physics marks:"); p=s.nextInt(); System.out.print("Enter chemistry marks:"); c=s.nextInt(); } void output() { System.out.println("Student no ::"+sno); System.out.println("Student name ::"+sname); System.out.println("Stuent maths marks ::"+m); System.out.println("Student physics marks ::"+p); System.out.println("Student chemistry marks ::"+c); } class Test1 { public static void main(String[] args) { Student s1=new Student(); s1.input(); s1.output(); } }

20th Jun 2017, 10:51 AM
Teja Sree
Teja Sree - avatar
4 Answers
+ 5
I don't know what is the problem with playground. In the IDE this code works. import java.util.Scanner; class Student {     int sno;     String sname;     int m;     int p;     int c;     void input() {         System.out.print("Enter the student number:");         sno = new Scanner(System.in).nextInt();         System.out.print("Enter the student name:");         sname = new Scanner(System.in).nextLine();         System.out.print("Enter the student2 name:");         sname = new Scanner(System.in).nextLine();         System.out.print("Enter maths marks:");         m = new Scanner(System.in).nextInt();         System.out.print("Enter physics marks:");         p = new Scanner(System.in).nextInt();         System.out.print("Enter chemistry marks:");         c = new Scanner(System.in).nextInt();     }     void output() {         System.out.println("Student no  ::" + sno);         System.out.println("Student name  ::" + sname);         System.out.println("Stuent maths marks  ::" + m);         System.out.println("Student physics marks  ::" + p);         System.out.println("Student chemistry marks  ::" + c);     } } class Test1 {     public static void main(String[] args)     {         Student s1=new Student();         s1.input();         s1.output();     } }
20th Jun 2017, 12:54 PM
Alexey
Alexey - avatar
+ 6
You can not put methods outside of a class
20th Jun 2017, 11:06 AM
Alexey
Alexey - avatar
+ 1
thank u
20th Jun 2017, 2:25 PM
Teja Sree
Teja Sree - avatar
0
can you re_right the program
20th Jun 2017, 11:09 AM
Teja Sree
Teja Sree - avatar