- 3
28th Mar 2022, 1:53 PM
Sidharth Patnaik
23 Respostas
0
Sidharth Patnaik Still xyz declared 2 times. Check my shared code
29th Mar 2022, 9:02 AM
A͢J
A͢J - avatar
+ 7
Sidharth Patnaik Many mistakes 1 - main method missing 2 - String not string in get method 3 - declaration of 'i' in for loop is missing 4 - else can't have condition so there should be else if() 5 - semicolon (;) should not be after if condition because it would stop execution and inside if block code will not execute. 6 - declaration of 'z' is missing 7 - class name should start from Capital letter "Xyz" Basically you need to learn how to use syntax properly.
28th Mar 2022, 2:20 PM
A͢J
A͢J - avatar
+ 3
Sidharth Patnaik No still not right As I told in first reply learn how to use syntax properly 1 - make variables private 2 - In main method there should be (String[] args) 3 - You have created same class 2 times 4 - print inside get method 5 - Class object should be like: xyz obj = new xyz(); //you have written obj() 6 - you have 1 method get which accept 1 argument, so obj.get(); not make sense here is right solution: https://code.sololearn.com/c8CEOIVtZU4H/?ref=app
29th Mar 2022, 8:49 AM
A͢J
A͢J - avatar
+ 2
Your 1st "else" would need to be an "else if". edit: * you deleted the main method and never called getX() – you need to pass a string to getX() * you missed to declare variables like i or z * your conditions fails, as you confused AND and OR: an integer cannot be greater than 65 and smaller than 90 at the same time * CharAt() returns an character – you need to convert it to an integer * if you specify a condition, you cannot use an else, you need if or else if, respectively
28th Mar 2022, 2:02 PM
Lisa
Lisa - avatar
+ 2
Sidharth Patnaik Yes but print inside method so you can get output
29th Mar 2022, 9:02 AM
A͢J
A͢J - avatar
+ 2
Sidharth Patnaik Print these lines inside get method: System .out.println ("total number of capital="+toup); System .out.println ("total number of small="+tolow); System .out.println ("total number of space="+space); And change second class xyz (which has main method) with other name like Abc
29th Mar 2022, 9:08 AM
A͢J
A͢J - avatar
+ 1
Try to do again by following suggestion posted above ones and reply with update code. If you don't understand anything then you can ask about that specific doubt.. Giving only code will not help you... hope you understand it.
28th Mar 2022, 3:18 PM
Jayakrishna 🇮🇳
+ 1
Where is main method? To run it, you must need main method. Add main method and call this method from main method... edit : Sidharth Patnaik see this , revise the lessons after: class xyz { //this is method, execution starts from here public static void main(String []arg) { get("AbcdE"); // calling the method } public static void get(String x) { int toup=0, tolow=0, space =0; // add in method otherwise you need an object to use those or make static variables for(int i=0;i<x.length();i++) { char z=x.charAt(i); if (z>=65 && z<=90) { toup++; } else if(z>=97 && z<=120) { tolow++; } else { space++; } } System.out.println ("total number of capital = "+toup); System.out.println ("total number of small = "+tolow); } }
28th Mar 2022, 3:29 PM
Jayakrishna 🇮🇳
+ 1
class xyz { int toup=0; int tolow=0; int space =0; void get(String x) { for (int i=0;i<x.length();i++) { char z=x.charAt(i); if (z>=65 && z<=90) { toup++; } else if(z>=97 && z<=120) { tolow++; } else { space++; } } } System .out.println ("total number of capital="+toup); System .out.println ("total number of small="+tolow); System .out.println ("total number of space="+space); } public class xyz { public static void main(String[] args) { xyz obj=new xyz(); obj.get("Sidharth Patnaik"); } }
29th Mar 2022, 8:59 AM
Sidharth Patnaik
+ 1
Yeah now its done❤
29th Mar 2022, 9:08 AM
Sidharth Patnaik
0
Can u solve my answer please
28th Mar 2022, 2:26 PM
Sidharth Patnaik
0
class xyz { int toup=0; int tolow=0; int space =0; void get(String x) { for (int i=0;i<x.length();i++) { char z=x.charAt(i); if (z>=65 && z<=90) { toup++; } else if(z>=97 && z<=120) { tolow++; } else { space++; } } System .out.println ("total number of capital="+toup); System .out.println ("total number of small="+tolow); } }
28th Mar 2022, 3:25 PM
Sidharth Patnaik
0
It showing no output
28th Mar 2022, 3:25 PM
Sidharth Patnaik
0
Thank you sir,now i understood
28th Mar 2022, 4:38 PM
Sidharth Patnaik
0
The open site chefra
29th Mar 2022, 6:38 AM
WOLKEN _YT
0
class xyz { int toup=0; int tolow=0; int space =0; void get(String x) { for (int i=0;i<x.length();i++) { char z=x.charAt(i); if (z>=65 && z<=90) { toup++; } else if(z>=97 && z<=120) { tolow++; } else { space++; } } } System .out.println ("total number of capital="+toup); System .out.println ("total number of small="+tolow); System .out.println ("total number of space="+space); } public class xyz { public static void main(String args) { xyz obj=new obj(); obj.get("Sidharth Patnaik"); obj.get(); } }
29th Mar 2022, 8:28 AM
Sidharth Patnaik
0
Is it correct now??
29th Mar 2022, 8:29 AM
Sidharth Patnaik
0
//corrected code. // read comments, for changes made class xyz { int toup=0; int tolow=0; int space =0; void get(String x) { for (int i=0;i<x.length();i++) { char z=x.charAt(i); if (z>=65 && z<=90) toup++; else if(z>=97 && z<=120) tolow++; else{ space++; } } System .out.println ("total number of capital = "+toup); System .out.println ("total number of small = "+tolow); System .out.println ("total number of space = "+space); } } //add this to end of class xyz class Main //class name must be different in same file { public static void main(String args[]) // Argument must br string of array, not srring. { xyz obj=new xyz(); // creating object of xyz() , its not obj() obj.get("Sidharth Patnaik"); //obj.get(); you dont have get() method without parameter } }
29th Mar 2022, 8:58 AM
Jayakrishna 🇮🇳
0
Now is it correct
29th Mar 2022, 8:59 AM
Sidharth Patnaik
0
If i change it showing error
29th Mar 2022, 9:05 AM
Sidharth Patnaik