Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
classwork
//'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,word=""; for(int x=0; x < k; x++) { for(int y=1; y < (k-x); y++) { if(arr[y-1] > arr[y]) { temp = ar[y-1]; ar[y-1] = ar[y]; ar[y] = temp; } } } for(int x=0; x<k; x++) System.out.print(arr[x]+" "); } else System.out.println("Invalid input"); } }
run
|
edit
|
history
|
help
0
Implementation of several common methods of LinkedList
2c
쓰레드 critical section
Iterative Merge sort
name
// Java Coding Challenge - 10: Palindrome numbers
Java Variable
ok
Hi
1(D)