Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Abhay
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter a sentence"); String ss=sc.nextLine(); ss+=" "; String wrd=""; String arr[]=new String[500]; int ar[]=new int[500]; int k=0; int ln=ss.length(); char ch=ss.charAt(ln-2); if(ch=='.'||ch==','||ch=='?'||ch=='!') { for(int i=0; i<ln-1; i++) { char c=ss.charAt(i); if(c!=' ') wrd+=c; else { int s=0; int ln2=wrd.length(); for(int j=0; j<ln2; j++) { char ch2=wrd.charAt(j); s+=(int)ch2; } arr[k]=wrd; ar[k]=s; wrd=""; k++; } } int temp = 0; String word=""; for(int i=0; i<k-1; i++) { for(int j=i+1; j<k; j++) { if(ar[i]>ar[j]) { temp = ar[i]; ar[i] = ar[j]; ar[j]= temp; word =arr[i]; arr[i]=arr[j]; arr[j]=word; } } } for(int x=0; x<k; x++) System.out.print(arr[x]+" "); } else System.out.println("Invalid input"); } }
run
|
edit
|
history
|
help
0
// Java Coding Challenge - 08: Reversing a Number using StringBuilder
ElaineBrown**
Java messing around
jb14.0 tests
Item battle rolyal
Graph adjacency list representation
rstring
update
Main.java
arithematic